<?php
/**
 * Created by PhpStorm.
 * User: ZL
 * Date: 2016/4/19
 * Time: 10:54
 */
namespace Api\Controller;

class DataController extends BaseController
{
    public function customerAuthentication(){
        $room_id = I('param.room_id');
        $wxcus_id = I('param.customer_id');
        if(!$room_id || !$wxcus_id){
            $data['status'] = 0;
            $data['sign'] = '缺少房间id或用户id!';
            $this->ajaxReturn($data);
        }
        $roomData = M('Room')->find($room_id);
        //有没有房间
        if(!$roomData) {
            $data['status'] = 0;
            $data['sign'] = '无房间信息!';
            $this->ajaxReturn($data);
        }
        $family_id = D('Customer')->findFamily($room_id);
        $customerData = D('Customer')->attestation($wxcus_id);
//        myDump($customerData);
//        myDump($family_id);
        D('Customer')->findMember($family_id,$customerData);
        $data = array();
        $data['status'] = 1;
        $data['crm_id'] = $customerData['id'];
        $data['sign'] = '认证成功!';
        $this->ajaxReturn($data);
    }

    public function accountPay()
    {
        $id = I('param.id');
        $data = array();
        $data['id'] = $id;
        $data['pay_time'] = I('pay_time');
        $data['payer_name'] = I('param.payer_name');
        $data['pay_money'] = I('param.pay_money');
        if(!$id || !$data['pay_time'] || !$data['payer_name'] || !$data['pay_money']){
            $data['status'] = 0;
            $data['sign'] = '请传入账单id,支付金额,支付人名字和支付时间!';
            $this->ajaxReturn($data);
        }
        $have = M('Account')->find($id);
        if(!$have){
            $data = array();
            $data['status'] = 0;
            $data['sign'] = '未找到账单!';
            $this->ajaxReturn($data);
        }
        $is_ok = D('Assistant/Account')->pay(false);
        if($is_ok){
            $data = array();
            $data['status'] = 1;
            $this->ajaxReturn($data);
        }
        $data = array();
        $data['status'] = 0;
        $data['sign'] = '金额超出账单未支付金额!';
        $this->ajaxReturn($data);
    }

    public function accountLook(){
//        $id = I('id');
//        $time = I('time');
//        if($id ){
//
//        }
    }

}
